package com.flash.BusinessData.controller;


import com.flash.BusinessData.entity.MarketData;
import com.flash.BusinessData.service.MarketDataService;
import com.flash.CashAdministration.entity.FundsAllot;
import com.flash.GlobalManagement.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 行情数据表
 */
@RestController
public class MarketDataController {
    @Autowired
    private MarketDataService marketDataService;

    @Resource
    Dbutil dbutil;

    // 查询
    @RequestMapping("MarketDataSelect")
    public Map selectUserDemo(int page,int limit,MarketData marketData){
        System.out.println("这是查询测试");
        List<MarketData> marketDataList = marketDataService.SelectMarketData(page, limit, marketData);
        System.out.println(marketDataList);
        int i = marketDataService.SelectCountMarkData();
        System.out.println(marketData);
        System.out.println(i);
        Map map =new HashMap();
        map.put("code","0");
        map.put("msg","");
        map.put("count",i);
        map.put("data",marketDataList);
        return map;
    }

    // 添加
    @RequestMapping("MarketDataInsert")
    public int InsertMarketData(MarketData marketData,HttpServletRequest request){
        System.out.println("我是增加");

        marketData.setMarketId(NumberUtil.getNumber(TableIdUtil.MID, TableNameUtil.M,"M"));
        HttpSession session = request.getSession();
        marketData.setFundId((String) session.getAttribute("fundId"));
        int i = marketDataService.InsertMarkeData(marketData);
        return i;
    }

    @RequestMapping("deleteMarketData")
    public int deleteMarketData(String marketId){
        System.out.println("我是删除");
        System.out.println(marketId);
        int i = marketDataService.DeleteMarkeData(marketId);
        System.out.println(i);

        return i;
    }

    @RequestMapping("UpdateMarketData")
    public int UpdateMarketData(MarketData marketData){
        System.out.println("我是修改");
        int i = marketDataService.UpdateMarkeData(marketData);
        System.out.println(i);
        return i;
    }
}
